<template>
	<view class="" style="position: relative;" v-if="is_jia">
		<view style="background-color: #F8F8F8;width: 100%;height: 100rpx; top: 0;left: 0; z-index: 88; position: sticky;
			border-radius: 10rpx;">
			<view class="banmi_flex j-b">
				<view class="banmi_flex j-c a-c" style="width: 180rpx;height: 100rpx;">
					<text>添加/编辑</text>
				</view>
				<view class="">
					<button @click="on_fan" class="banmi_flex j-c a-c" style="width: 120rpx;height: 100rpx;">
						<text>关闭</text>
					</button>
				</view>
			</view>
		</view>
		<view class="" style="height: 20rpx;">
		</view>
		<view>
			<view class="banmi_flex" style="">
				<view class="  p-20" style="width: 100%;padding-right: 60px;padding-left: 20px;">
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							账号
						</view>
						<uni-easyinput v-model="find.account" placeholder="请输入账号">
						</uni-easyinput>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							手机号
						</view>
						<uni-easyinput v-model="find.tel" placeholder="请输入手机号">
						</uni-easyinput>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							密码
						</view>
						<uni-easyinput v-model="find.password" placeholder="请输入密码">
						</uni-easyinput>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							确定密码
						</view>
						<uni-easyinput v-model="find.news_password" placeholder="请输入确认密码">
						</uni-easyinput>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							名称
						</view>
						<uni-easyinput v-model="find.nickname" placeholder="请输入名称">
						</uni-easyinput>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">
							角色
						</view>
						<uni-data-select @change="on_change" :localdata="list_nav" :value="nav_id" placeholder="选择分类">
						</uni-data-select>
					</view>
					<view class="banmi_flex a-c  p-b-10">
						<view class="f-14 c-7" style="width: 100px;">

						</view>
						<view class="banmi_flex j-c a-c" style="width: 150rpx;height: 100rpx;">
							<button type="default" @click="subQuestion" class="sub_btn">保存</button>
						</view>
					</view>

					<view class="" style="height: 120px;">
					</view>
				</view>
			</view>
		</view>



	</view>
</template>

<script>
	import popup from '@/uni_modules/uni-popup/components/uni-popup/popup.js'
	import choose from "@/common/image/choose.vue"
	import compress from "@/common/image/compress.vue"
	import adminAdmin from '@/mi/admin_admin.vue';
	export default {
		components: {

			choose,
			compress,
			adminAdmin
		},
		name: "uniPopupDialog",
		mixins: [popup],
		emits: ['confirm', 'close'],
		props: {
			windowHeight: {
				type: Number,
				default () {
					return 0;
				}
			},
			windowWidth: {
				type: Number,
				default () {
					return 0;
				}
			},
			id: {
				type: Number,
				default () {
					return 0;
				}
			},
			img_url: {
				type: String,
				default () {
					return '';
				}
			},
		},
		data() {
			return {
				find: {
					nickname: '',
					account: '',
					password: '',
					news_password: '',
					tel: ''
				},
				count: 1,
				maxwh: 500,
				is_jia: false,
				tab_i: 0,
				stock: '',
				mp4: '',
				quality: 1,
				imgList: [],
				menu_list: [],
				nav_id: 0,
				list_nav: []




			}
		},
		mounted() {


			this.is_ajax = false;

			if (this.id > 0) {
				this.init_finds();
			} else {
				this.is_jia = true;
			}
			this.init();
		},

		methods: {
			on_change(index) {
				this.nav_id = index;
			},
			init_finds() {
				var that = this;
				let requestParams = {
					id: this.id,
				};
				this.Htpp.post('/admin.admin/admin_finds', {
					token: false,
					datalist: requestParams
				}).then(ret => {

					if (ret.data.status == 200) {
						this.find = ret.data.data.find
						this.find.password = '';
						this.nav_id = this.find.role_id

					}
				})
			},

			init() {
				var that = this;
				let requestParams = {
					id: this.id,
				};
				this.Htpp.post('/admin.Saaslist/admin_list', {
					token: false,
					datalist: requestParams
				}).then(ret => {

					if (ret.data.status == 200) {
						var list_nav = ret.data.data.list
						for (var i = 0; i < list_nav.length; i++) {
							list_nav[i]['text'] = list_nav[i]['role_name'];
							list_nav[i]['value'] = list_nav[i]['id'];
						}
						this.list_nav = list_nav;
						this.is_jia = true;

					}
				})
			},
			fileChange(e, index, videow, videoh) {
				this.imgList = e;

			},
			subQuestion() {


				if (!this.find['account']) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					})
					return
				}
				if (!this.find['nickname']) {
					uni.showToast({
						title: '请输入账号名称',
						icon: 'none'
					})
					return
				}
				if (this.nav_id == 0) {
					uni.showToast({
						title: '请选择角色',
						icon: 'none'
					})
					return
				}
				if (this.id > 0) {
					if (this.find['password'] && this.find['password'] != this.find['news_password']) {
						uni.showToast({
							title: '密码和确认密码不一致',
							icon: 'none'
						})
						return
					}
					this.ok_ajax();
					return
				}

				if (!this.find['password']) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
					return
				}
				if (this.find['password'] != this.find['news_password']) {
					uni.showToast({
						title: '密码和确认密码不一致',
						icon: 'none'
					})
					return
				}





				this.ok_ajax();

			},


			on_fan() {
				this.popup.close()
			},

			ok_ajax() {
				var that = this;
				let requestParams = {

					nickname: this.find['nickname'],
					password: this.find['password'],
					account: this.find['account'],
					tel: this.find['tel'],
					nav_id: this.nav_id,
					id: this.id
				};
				this.Htpp.post('/admin.admin/admin_add', {
					token: false,
					datalist: requestParams
				}).then(ret => {
					uni.showToast({
						title: ret.data.msg,
						icon: 'none'
					})

					if (ret.data.status == 200) {
						that.$emit('img_ok')
						that.popup.close()
					}
				})
			},
		}
	}
</script>

<style>
	button {
		padding: 0;

		background: transparent;
	}

	.zu_but {
		position: fixed;
		height: 100rpx;
		z-index: 999;
		background-color: #F8F8F8;
		bottom: 288rpx;
	}

	.option_box {
		width: 35rpx;
		height: 35rpx;
		border: 1rpx solid #999999;
		border-radius: 5px;
		margin-right: 10rpx;
		// background-color: #FF852A;
		display: flex;
		justify-content: center;
		align-items: center;

		image {
			width: 20rpx;
			height: 20rpx;
		}
	}

	.option_box_active {
		background: linear-gradient(-30deg, #ff7029 0%, #faa307 100%);
		border: 1rpx solid #faa307 !important;
	}

	.sub_btn_add {
		margin-left: 30rpx;
		width: 150rpx;
		height: 60rpx;
		background: linear-gradient(-30deg, #A9A9A9 0%, #A9A9A9 100%);
		border-radius: 44rpx;

		font-size: 30rpx;
		font-weight: 700;
		color: #ffffff;

		line-height: 60rpx;
	}

	.sub_btn {
		width: 150rpx;
		height: 70rpx;
		background: #0071FE;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #ffffff;
		line-height: 70rpx;
	}

	button::after {
		border: none;
	}
</style>